#ifndef _CONCERT_TICKET_H
#define _CONCERT_TICKET_H

#include "list.h"

#define FALSE         (0)
#define TRUE          (1)

enum {
	TICKET_PARAM_NULL = 1,
	TICKET_OPEN_FILE_FAIL,
	TICKET_WRITE_FILE_FAIL,
	CONCERT_ENCIPHER_FAIL,
	CONCERT_DECIPHER_FAIL,
};


#define CONCERT_TICKET_FILE  "./lib/concert_ticket.txt"
#define USER_INFO_FILE       "./lib/user_info.txt"
#define LIB_DIR              "./lib"

struct concert_ticket {
	char ID[6];
	char artist[3];
	char show_time[5];
	char price[3];
	char spare_ticket_num[4];
	char total_ticket_num[4];
	struct list_head list;
};

#define USER_ACCOUNT_LENGTH     (11)
#define OWN_TICKET_MAX          (5)
#define TICKET_ID_LENGTH        (6)

struct booked_ticket_id {
	char ID[TICKET_ID_LENGTH];
	struct list_head list;
};

struct user_info {
	char account [USER_ACCOUNT_LENGTH];
	char own_ticket[OWN_TICKET_MAX][TICKET_ID_LENGTH];
	unsigned int own_ticket_count;
};


extern int concert_ticket_init(struct list_head *p_ticket_head,
							   struct list_head *p_booked_ticket_id_head);

extern int display_concert_ticket(struct list_head *p_ticket_head, int num);

extern int load_user_info(char *account,
						  struct user_info *p_user_info,
						  struct list_head *p_booked_ticket_id_head);
extern int logout_user_info(struct user_info *p_user_info,
							struct list_head *p_booked_ticket_id_head);
extern int display_user_ticket_id(struct list_head *p_booked_ticket_id_head);
extern int display_user_ticket(struct list_head *p_booked_ticket_id_head,
							   struct list_head *p_ticket_head);

extern int book_concert_ticket(struct user_info *p_user_info,
							   struct list_head *p_booked_ticket_id_head,
							   struct list_head *p_ticket_head,
							   char *ID);
extern int return_concert_ticket(struct user_info *p_user_info,
								 struct list_head *p_booked_ticket_id_head,
								 struct list_head *p_ticket_head,
								 char *ID);

extern int concert_ticket_destroy(struct list_head *p_ticket_head,
								  struct user_info *p_user_info,
								  struct list_head *p_booked_ticket_id_head);

#endif
